Precompute crc32 on GPX lookup table on startup so we spend less time
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 24 Jan 2006 15:30:54 +0000 (15:30 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 24 Jan 2006 15:30:54 +0000 (15:30 +0000)
in strcmp later.

gpsbabel/Makefile
gpsbabel/defs.h
gpsbabel/gpx.c
gpsbabel/mingw/wintesto.cmd
gpsbabel/util_crc.c

index adc75426bb789ad7849ab33729e180ceced67259..f8ec88b7ce0f129914ac00dfa70da7db7b639ee8 100644 (file)
@@ -1,7 +1,7 @@
 
 VERSU=1_2_8
 VERSD=1.2.8
-RELEASE=-beta12012005-clyde
+RELEASE=-beta01182006-clyde
 VERSIONU=$(VERSU)$(RELEASE)
 VERSIOND=$(VERSD)$(RELEASE)
 
index bf5f9304f7ad134c66b0c688af83bb46ff2d8e3f..76ca729ac10d3051587c160226f51f3a9c5cc2c1 100644 (file)
@@ -688,6 +688,7 @@ double degrees2ddmm(double deg_val);
  *  From util_crc.c
  */
 unsigned long get_crc32(const void * data, int datalen);
+unsigned long get_crc32_s(const void * data);
 
 /*
  * Color helpers.
index b6cf88acd2b0a4e94d05ecdcb029e894500be5c8..887705dce562c669e2c464ba3019a09317647941 100644 (file)
@@ -235,6 +235,7 @@ typedef struct tag_mapping {
        tag_type tag_type;              /* enum from above for this tag */
        int tag_passthrough;            /* true if we don't generate this */
        const char *tag_name;           /* xpath-ish tag name */
+       unsigned long crc;              /* Crc32 of tag_name */
 } tag_mapping;
 
 /*
@@ -333,8 +334,10 @@ static tag_type
 get_tag(const char *t, int *passthrough)
 {
        tag_mapping *tm;
+       unsigned long tcrc = get_crc32_s(t);
+
        for (tm = tag_path_map; tm->tag_type != 0; tm++) {
-               if (0 == strcmp(tm->tag_name, t)) {
+               if ((tcrc == tm->crc) && (0 == strcmp(tm->tag_name, t))) {
                        *passthrough = tm->tag_passthrough;
                        return tm->tag_type;
                }
@@ -343,6 +346,15 @@ get_tag(const char *t, int *passthrough)
        return tt_unknown;
 }
 
+static void
+prescan_tags(void)
+{
+       tag_mapping *tm;
+       for (tm = tag_path_map; tm->tag_type != 0; tm++) {
+               tm->crc = get_crc32_s(tm->tag_name);
+       }
+}
+
 static void
 tag_gpx(const char **attrv)
 {
@@ -1043,6 +1055,8 @@ gpx_rd_init(const char *fname)
        file_time = 0;
        current_tag = vmem_alloc(1, 0);
        *((char *)current_tag.mem) = '\0';
+
+       prescan_tags();
        
        psr = XML_ParserCreate(NULL);
        if (!psr) {
index 6cdbb88d251652a8575809ae431a997e53174c58..4866ba53abe389c73fd9fc030387ac6ea3ec48af 100644 (file)
@@ -3,6 +3,7 @@ REM
 REM Simple Windows NT/2000/XP .cmd version of GPSBabel testo script\r
 REM\r
 \r
+SET GPSBABEL_FREEZE_TIME=y\r
 SET TMPDIR=%TEMP%\WINTESTO\r
 MKDIR %TMPDIR% 2>NUL:\r
 \r
@@ -18,8 +19,8 @@ FOR %%A IN (%3) DO IF "d--------"=="%%~aA" SET PARAM2=%3\*
 FOR /f "delims=" %%a IN ('fc %PARAM1% %PARAM2%') DO IF "x%%a"=="xFC: no differences encountered" GOTO :EOF\r
 REM Show the first 5 lines of difference\r
 fc %1 /LB5 %PARAM1% %PARAM2%\r
-ECHO %* are not the same (first 5 differences above) - pausing. ^C to quit if required\r
-PAUSE\r
+if errorlevel 1 ECHO %* are not the same (first 5 differences above) - pausing. ^C to quit if required\r
+if errorlevel 1 PAUSE\r
 GOTO :EOF\r
 \r
 REM ==================================\r
@@ -47,6 +48,8 @@ REM ==================================
 :REALSTART\r
 \r
 \r
+REM Turn on GNU libc instrumentation.\r
+\r
 SET PNAME=.\gpsbabel\r
 IF NOT EXIST %PNAME%.EXE ECHO Can't find %PNAME%&& GOTO :EOF\r
 \r
@@ -54,6 +57,16 @@ IF NOT EXIST %PNAME%.EXE ECHO Can't find %PNAME%&& GOTO :EOF
 \r
 \r
 \r
+REM Some formats are just too boring to test.   The ones that\r
+REM are xcsv include \r
+REM garmin301 \r
+REM garmin_poi \r
+REM gpsdrivetrack\r
+REM nima \r
+REM mapconverter\r
+REM geonet\r
+REM saplus\r
+REM s_and_t\r
 REM Geocaching .loc\r
 DEL %TMPDIR%\gl.loc\r
 @echo on\r
@@ -196,8 +209,17 @@ DEL %TMPDIR%\mm.pcx %TMPDIR%\pcx.gps
 @echo off\r
 @echo.\r
 CALL :COMPARE %TMPDIR%\mm.gps %TMPDIR%\gu.wpt\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -t -i gpx -f reference\track\tracks.gpx -o pcx -F %TMPDIR%\pcx.trk\r
+%PNAME% -t -i pcx -f reference\track\pcx.trk -o pcx -F %TMPDIR%\pcx2.trk\r
+@echo off\r
+@echo.\r
+CALL :COMPARE %TMPDIR%\pcx.trk %TMPDIR%\pcx2.trk \r
 \r
+REM \r
 REM Magellan file format\r
+REM \r
 @echo on\r
 @echo Testing...\r
 %PNAME% -i magellan -f reference\magfile -o magellan -F %TMPDIR%\magfile\r
@@ -205,6 +227,17 @@ REM Magellan file format
 @echo.\r
 CALL :COMPARE %TMPDIR%\magfile reference\magfile\r
 \r
+REM \r
+REM Magellanx is just like, but with longer names. (which this admittedly\r
+REM doesn't actually exercise...)\r
+REM \r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i magellan -f reference\magfile -o magellanx -F %TMPDIR%\magfile2\r
+@echo off\r
+@echo.\r
+CALL :COMPARE %TMPDIR%\magfile2 reference\magfile\r
+\r
 REM Navitrak DNA marker format\r
 @echo on\r
 @echo Testing...\r
@@ -522,6 +555,7 @@ DEL %TMPDIR%\magellan.rte
 @echo.\r
 CALL :COMPARE %TMPDIR%\magellan.rte reference\route\magellan.rte\r
 \r
+\r
 REM \r
 REM GPX routes -- since GPX contains a date stamp, tests will always\r
 REM fail, so we use magellan as an interim format...\r
@@ -626,6 +660,7 @@ REM CoastalExplorer..
 %PNAME% -r -i coastexp -f reference\coastexp.nob -o gpx -F %TMPDIR%\coastexp.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\coastexp.gpx reference\coastexp.ref\r
 @echo on\r
 @echo Testing...\r
 %PNAME% -r -i gpx -f %TMPDIR%\coastexp.gpx -o coastexp -F %TMPDIR%\coastexp.nob\r
@@ -637,6 +672,7 @@ CALL :COMPARE %TMPDIR%\coastexp.nob reference\coastexp.ref2
 %PNAME% -w -i coastexp -f reference\coastexp.nob -o gpx -F %TMPDIR%\coastexp.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\coastexp.gpx reference\coastexp.ref3\r
 @echo on\r
 @echo Testing...\r
 %PNAME% -w -i gpx -f %TMPDIR%\coastexp.gpx -o coastexp -F %TMPDIR%\coastexp.nob\r
@@ -777,6 +813,13 @@ DEL %TMPDIR%\gn.pdb %TMPDIR%\1.gpx %TMPDIR%\2.gpx
 @echo off\r
 @echo.\r
 CALL :COMPARE %TMPDIR%\1.gpx %TMPDIR%\2.gpx\r
+REM \r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i geoniche -f reference\gn-targets.pdb -o gpx -F %TMPDIR%\gn-targets.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE %TMPDIR%\gn-targets.gpx reference\gn-targets.gpx\r
 \r
 REM \r
 REM saroute covers *.anr, *.rte, and *.rtd, but I only have an .anr for testing.\r
@@ -831,6 +874,7 @@ CALL :COMPARE %TMPDIR%\igc_sed.out reference\igc1_igc.out
 %PNAME% -i igc -f %TMPDIR%\igc.out -o gpx -F %TMPDIR%\igc.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\igc.gpx reference\igc1_gpx.out\r
 \r
 @echo on\r
 @echo Testing...\r
@@ -854,6 +898,7 @@ CALL :COMPARE %TMPDIR%\igc_sed.out reference\igc1_3d.out
 %PNAME% -i igc -f reference\igc2.igc -o gpx -F %TMPDIR%\igc.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\igc.gpx reference\igc2_gpx.out\r
 \r
 @echo on\r
 @echo Testing...\r
@@ -868,6 +913,7 @@ CALL :COMPARE %TMPDIR%\igc_sed.out reference\igc2_igc.out
 %PNAME% -i igc -f %TMPDIR%\igc.out -o gpx -F %TMPDIR%\igc.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\igc.gpx reference\igc2_gpx.out\r
 \r
 REM \r
 REM Google Maps XML test\r
@@ -875,18 +921,26 @@ REM
 DEL %TMPDIR%\google.out\r
 @echo on\r
 @echo Testing...\r
-%PNAME% -i google -f reference\google.xml -o arc -F %TMPDIR%\google.out\r
+%PNAME% -i google -f reference\google.xml -o csv -F %TMPDIR%\google.out\r
 @echo off\r
 @echo.\r
-CALL :COMPARE %TMPDIR%\google.out reference\google.arc\r
+CALL :COMPARE %TMPDIR%\google.out reference\google.csv\r
 \r
 DEL %TMPDIR%\google.out\r
 @echo on\r
 @echo Testing...\r
-%PNAME% -i google -f reference\google.js -o arc -F %TMPDIR%\google.out\r
+%PNAME% -i google -f reference\google.js -o csv -F %TMPDIR%\google.out\r
 @echo off\r
 @echo.\r
-CALL :COMPARE %TMPDIR%\google.out reference\google.arc\r
+CALL :COMPARE %TMPDIR%\google.out reference\google.csv\r
+\r
+DEL %TMPDIR%\google.out\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i google -f reference\google_jan_06.html -o csv -F %TMPDIR%\google.out\r
+@echo off\r
+@echo.\r
+CALL :COMPARE %TMPDIR%\google.out reference\google_jan_06.csv\r
 \r
 REM \r
 REM DeLorme .an1 tests\r
@@ -905,7 +959,7 @@ DEL %TMPDIR%\an1.out
 %PNAME% -i an1 -f reference\foo.an1 -o an1 -F %TMPDIR%\an1.out\r
 @echo off\r
 @echo.\r
-CALL :COMPARE %TMPDIR%\an1.out reference\an1-an1.ref\r
+CALL :BINCOMPARE %TMPDIR%\an1.out reference\an1-an1.ref\r
 \r
 DEL %TMPDIR%\an1.out\r
 @echo on\r
@@ -913,7 +967,7 @@ DEL %TMPDIR%\an1.out
 %PNAME% -i xmap -f reference\xmap -o an1 -F %TMPDIR%\an1.out \r
 @echo off\r
 @echo.\r
-CALL :COMPARE %TMPDIR%\an1.out reference\an1-out.ref\r
+CALL :BINCOMPARE %TMPDIR%\an1.out reference\an1-out.ref\r
 \r
 DEL %TMPDIR%\an1.out\r
 @echo on\r
@@ -921,7 +975,7 @@ DEL %TMPDIR%\an1.out
 %PNAME% -i google -f reference\google.js -o an1 -F %TMPDIR%\an1.out\r
 @echo off\r
 @echo.\r
-CALL :COMPARE %TMPDIR%\an1.out reference\an1-line-out.ref\r
+CALL :BINCOMPARE %TMPDIR%\an1.out reference\an1-line-out.ref\r
 \r
 REM \r
 REM TomTom .ov2 tests\r
@@ -1021,19 +1075,21 @@ REM
 \r
 @echo on\r
 @echo Testing...\r
-%PNAME% -i geo -f geocaching.loc  -o tabsep -F - | %PNAME% -i tabsep -f - -o geo -F %TMPDIR%\tabsep.out\r
+%PNAME% -i geo -f geocaching.loc  -o tabsep -F %TMPDIR%\tabsep.in\r
+%PNAME% -i tabsep -f %TMPDIR%\tabsep.in -o geo -F %TMPDIR%\tabsep.out\r
 %PNAME% -i geo -f geocaching.loc  -o geo -F %TMPDIR%\geotabsep.out\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\tabsep.out %TMPDIR%\geotabsep.out\r
 \r
 REM \r
 REM Now do the same for custom - it has the same issues.\r
 REM \r
 \r
-CALL :COMPARE %TMPDIR%\tabsep.out %TMPDIR%\geotabsep.out\r
 @echo on\r
 @echo Testing...\r
-%PNAME% -i geo -f geocaching.loc  -o custom -F - | %PNAME% -i custom -f - -o geo -F %TMPDIR%\custom.out\r
+%PNAME% -i geo -f geocaching.loc  -o custom -F %TMPDIR%\custom.in\r
+%PNAME% -i custom -f %TMPDIR%\custom.in -o geo -F %TMPDIR%\custom.out\r
 %PNAME% -i geo -f geocaching.loc  -o geo -F %TMPDIR%\geocustom.out\r
 @echo off\r
 @echo.\r
@@ -1075,6 +1131,7 @@ DEL %TMPDIR%\pathaway*
 %PNAME% -t -i pathaway -f reference\track\pathaway.pdb -o gpx -F %TMPDIR%\pathaway.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\pathaway.gpx reference\track\pathaway.gpx\r
 \r
 REM \r
 REM Garmin GPS Database .gdb tests\r
@@ -1082,7 +1139,7 @@ REM
 DEL %TMPDIR%\gdb-*\r
 @echo on\r
 @echo Testing...\r
-%PNAME% -w -r -t -i gdb -f reference\gdb-sample.gdb -o gpx -F %TMPDIR%\gdb-sample.gpx\r
+%PNAME% -w -r -t -i gdb,via -f reference\gdb-sample.gdb -o gpx -F %TMPDIR%\gdb-sample.gpx\r
 @echo off\r
 @echo.\r
 CALL :COMPARE reference\gdb-sample.gpx %TMPDIR%\gdb-sample.gpx\r
@@ -1107,11 +1164,13 @@ DEL %TMPDIR%\vitosmt*
 %PNAME%    -i vitosmt -f reference\vitosmt.smt -o gpx -F %TMPDIR%\vitosmt.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\vitosmt.gpx reference\vitosmt.gpx\r
 @echo on\r
 @echo Testing...\r
 %PNAME% -t -i vitosmt -f reference\vitosmt.smt -o gpx -F %TMPDIR%\vitosmt_t.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\vitosmt_t.gpx reference\track\vitosmt_t.gpx\r
 \r
 REM \r
 REM tracks filter tests\r
@@ -1124,6 +1183,7 @@ DEL %TMPDIR%\trackfilter*
 %PNAME% -t -i gpx -f reference\track\trackfilter.gpx -x track,pack,split,title=LOG-%%Y%%m%%d -o gpx -F %TMPDIR%\trackfilter.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\trackfilter.gpx reference\track\trackfilter.gpx\r
 \r
 REM \r
 REM Map&Guide Motorrad Routenplaner .bcr files test\r
@@ -1134,6 +1194,7 @@ DEL %TMPDIR%\bcr*
 %PNAME% -r -i bcr -f reference\route\bcr-sample.bcr -o gpx -F %TMPDIR%\bcr-sample.gpx\r
 @echo off\r
 @echo.\r
+CALL :COMPARE %TMPDIR%\bcr-sample.gpx reference\route\bcr-sample.gpx \r
 @echo on\r
 @echo Testing...\r
 %PNAME% -r -i gpx -f reference\route\bcr-sample.gpx -o bcr -F %TMPDIR%\bcr-sample2.bcr\r
@@ -1373,3 +1434,77 @@ DEL %TMPDIR%\mag_pdb-*
 @echo.\r
 CALL :COMPARE %TMPDIR%\mag_pdb-sample.gpx reference\route\mag_pdb-sample.gpx\r
 \r
+REM \r
+REM CompeGPS I/O tests\r
+REM \r
+DEL %TMPDIR%\compegps*\r
+REM read (CompeGPS)\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i compegps -f reference\compegps.wpt -o gpx -F %TMPDIR%\compegps-wpt.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE reference\compegps-wpt.gpx %TMPDIR%\compegps-wpt.gpx\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i compegps -f reference\route\compegps.rte -o gpx -F %TMPDIR%\compegps-rte.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE reference\route\compegps-rte.gpx %TMPDIR%\compegps-rte.gpx\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i compegps -f reference\track\compegps.trk -o gpx -F %TMPDIR%\compegps-trk.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE reference\track\compegps-trk.gpx %TMPDIR%\compegps-trk.gpx\r
+REM write (CompeGPS)\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i compegps -f reference\compegps.wpt -o compegps -F %TMPDIR%\compegps.wpt\r
+%PNAME% -i compegps -f %TMPDIR%\compegps.wpt -o gpx -F %TMPDIR%\compegps-wpt2.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE reference\compegps-wpt.gpx %TMPDIR%\compegps-wpt2.gpx\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -t -i compegps -f reference\track\compegps.trk -o compegps -F %TMPDIR%\compegps.trk\r
+%PNAME% -i compegps -f %TMPDIR%\compegps.trk -o gpx -F %TMPDIR%\compegps-trk2.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE reference\track\compegps-trk.gpx %TMPDIR%\compegps-trk2.gpx\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -r -i compegps -f reference\route\compegps.rte -o compegps -F %TMPDIR%\compegps.rte\r
+%PNAME% -i compegps -f %TMPDIR%\compegps.rte -o gpx -F %TMPDIR%\compegps-rte2.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE reference\route\compegps-rte.gpx %TMPDIR%\compegps-rte2.gpx\r
+\r
+REM \r
+REM Testing the 'nuketypes' filter is funky.\r
+REM Convert a GPX file to GPX to eliminate jitter.\r
+REM Then nuke the all but the three individual types, merge the result together\r
+REM and verify we got the original back.\r
+REM \r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i gpx -f reference\gdb-sample.gpx -o gpx -F %TMPDIR%\alltypes.gpx\r
+%PNAME% -i gpx -f %TMPDIR%\alltypes.gpx -x nuketypes,tracks,routes -o gpx -F %TMPDIR%\wpts.gpx\r
+%PNAME% -i gpx -f %TMPDIR%\alltypes.gpx -x nuketypes,waypoints,routes -o gpx -F %TMPDIR%\trks.gpx\r
+%PNAME% -i gpx -f %TMPDIR%\alltypes.gpx -x nuketypes,waypoints,tracks -o gpx -F %TMPDIR%\rtes.gpx\r
+%PNAME% -i gpx -f %TMPDIR%\wpts.gpx -f %TMPDIR%\trks.gpx -f %TMPDIR%\rtes.gpx -o gpx -F %TMPDIR%\merged.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE %TMPDIR%\alltypes.gpx %TMPDIR%\merged.gpx\r
+\r
+REM \r
+REM Universal CSV - unicsv\r
+REM \r
+ECHO lat,lon,descr,name,notes,unk,unk> %TMPDIR%\unicsv.txt\r
+@echo on\r
+@echo Testing...\r
+%PNAME% -i unicsv -f %TMPDIR%\unicsv.txt -o gpx -F %TMPDIR%\unicsv.gpx\r
+@echo off\r
+@echo.\r
+CALL :COMPARE %TMPDIR%\unicsv.gpx reference\unicsv.gpx\r
+\r
index 390e66a77027a549a6b48fdf85f646817d908e2f..cba43adcbab1fde7b96a4a6668dce4765d1c3def 100644 (file)
@@ -79,3 +79,18 @@ get_crc32(const void * data, int datalen)
 
        return (crc ^ 0xFFFFFFFF);
 }
+
+/*
+ * As above, but on null-terminated string.
+ */
+unsigned long
+get_crc32_s(const void *data)
+{
+       unsigned long crc = 0xFFFFFFFF;
+       const unsigned char* cp = (unsigned char *)data;
+
+       for (;*cp;cp++) {
+               crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32_table[(crc ^ *cp) &0xFF];
+       }
+       return (crc ^ 0xFFFFFFFF);
+}